var nowDate = getDay(0);
var shopcode = sessionStorage.getItem("shopcode");
var userId = sessionStorage.getItem("userId");
var starttimecalendar = new lCalendar();
var endtimecalendar = new lCalendar();
var daibannum = 0;
var pageType = sessionStorage.getItem('pageType');
if(pageType == '' && sessionStorage.getItem("pageType") != 'null' && sessionStorage.getItem("pageType") != null){
	pageType = sessionStorage.getItem("pageType");
}
starttimecalendar.init({
	'trigger': '#startDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
endtimecalendar.init({
	'trigger': '#endDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
$(document).ready(function(){  //界面切换
	$('#name').text(sessionStorage.getItem("name"));
	$('#startDate').val(nowDate);
	$('#endDate').val(nowDate);
 	if(sessionStorage.getItem("Creload")=='true'){
	     window.location.reload();
		 sessionStorage.setItem("Creload", false);
	}else{
		pandianDaihuifu();
		FankuiDaihuifu();
		pandianDaizongjie();
		FankuiDaixiugai();
		FankuiDaiwancheng();
		pandianDaishenpi();
		if(pageType == 'pandian'){
			pandianZhong();
		}
		$('#menuDiv .row_w30').on('click',function(){
			$(this).siblings().removeClass('orange').removeClass('add_bd_o');
			$(this).addClass('orange').addClass('add_bd_o');
			if($(this).attr('showType') == 'pingjia'){
				getPandianJianchaPingjia();
				$('#pingjiaDiv').show();
				$('#daibanDiv').hide();
				$('#wanchengDiv').hide();
			}else if($(this).attr('showType') == 'daiban'){
				$('#pingjiaDiv').hide();
				$('#daibanDiv').show();
				$('#wanchengDiv').hide();
			}else{
				$('#pingjiaDiv').hide();
				$('#daibanDiv').hide();
				$('#wanchengDiv').show();
			}
		});
  }
	
});
//查询盘点待总结信息
function pandianDaizongjie(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.zongjieuserjobnumber=sessionStorage.getItem("jobnumber");
	sendData.zongjieFlag=0;
	$.ajax({
		url: "../pandianevery_jd/pandianDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#zongjieTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" onclick="pandianzongjie('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\')">总结</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#zongjieTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}

//跳转到盘点回复页面
function pandianzongjie(pandianid,shopcode,shopname){
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	window.location.href='toJiancha_jieguo_detail?pandianid='+pandianid+"&type=zongjie";
}
//查询盘点待回复信息
function pandianDaihuifu(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
//	sendData.huifuuser=userId;
	sendData.huifuuserjobnumber=sessionStorage.getItem("jobnumber")
	sendData.huifuFlag=0;
//	sendData.zongjieFlag=1;
	$.ajax({
		url: "../pandianevery_jd/pandianDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#dataTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" onclick="pandianhuifu('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\')">回复</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#dataTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}

//跳转到盘点回复页面
function pandianhuifu(pandianid,shopcode,shopname){
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	window.location.href='toJiancha_jieguo_detail?pandianid='+pandianid+"&type=huifu";
}

//查询盘点待回复信息
function FankuiDaihuifu(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.senduser=userId;
	sendData.flag=0;
	sendData.shenpiFlag=0;
	$.ajax({
		url: "../pandianevery_jd/FankuiDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" onclick="fankuihuifu('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\')">回复</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//跳转到反馈回复页面
function fankuihuifu(pandianid,shopcode,shopname){
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	window.location.href='toJiancha_wentifankui?pandianid='+pandianid+"&type=huifu";
}
//查询盘点待完成信息
function FankuiDaiwancheng(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.wanchenguser=userId;
	sendData.flag=2;
	$.ajax({
		url: "../pandianevery_jd/FankuiDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" onclick="fankuiwancheng('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\')">去完成</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//跳转到反馈待完成信息页面
function fankuiwancheng(pandianid,shopcode,shopname){
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	window.location.href='toJiancha_wentifankui?pandianid='+pandianid+"&type=wancheng";
}
//查询盘点反馈待修改信息
function FankuiDaixiugai(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.wanchengUser=userId;
//	sendData.flag=0;
	sendData.querenFlag=2;
	$.ajax({
		url: "../pandianevery_jd/FankuiDaihuifu"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" onclick="fankuixiugai('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\')">修改</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//跳转到反馈待修改信息页面
function fankuixiugai(pandianid,shopcode,shopname){
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	window.location.href='toJiancha_wentifankui?pandianid='+pandianid+"&type=xiugai";
}
//查询盘点待审批信息
function pandianDaishenpi(){
	var sendData = {};
//	sendData.shopcode=$('#pandianShop').val();
	sendData.querenUser=sessionStorage.getItem("userId");
	sendData.querenFlag=0;
	$.ajax({
		url: "../pandianevery_jd/getPandianJiancha"
		,type:'post'
//		,async: false
		,data:JSON.stringify(sendData)
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res)
			
//			$('#zongjieTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange" onclick="pandianshenpi('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\')">审批</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#zongjieTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//跳转到盘点审批页面
function pandianshenpi(pandianid,shopcode,shopname){
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	window.location.href='toJiancha_jieguo_detail?pandianid='+pandianid+"&type=queren";
}
//查询待盘点数据
function pandianZhong(){
	var sendData = {};
	sendData.latitude='37.862444';
	sendData.longitude='112.546997';
	sendData.pandianDate= nowDate;
	sendData.flag = '1,10';
	sendData.nolimit = 'true';
//	sendData.notFlag=0;
	$.ajax({
		url: "../pandianevery_jd/getShopWeizhi",
		type : 'POST',
		data: JSON.stringify(sendData),
		contentType: "application/json; charset=utf-8",
		dataType : "json",
		success : function(res) {
			console.log(res)
			
//			$('#fankuiTable').empty();
			if(res.success){
				var resdata = res.data;
				daibannum += resdata.length;
				$('#daibannum').text(daibannum);
				for (var i = 0; i < resdata.length; i++) {
					$('#dataTable').append('<tr class="thin-border-bottom" onclick="startPandian('+resdata[i].id+',\''+resdata[i].shopcode+'\',\''+resdata[i].shopname+'\','+resdata[i].flag+',\''+resdata[i].sEmployeeNO+'\',\''+resdata[i].sEmployeeName+'\','+resdata[i].longitude+',\''+resdata[i].latitude+'\',\''+resdata[i].address+'\')">'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopcode+'</td>'
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].shopname+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">'+resdata[i].pandianDate+'</td>'//id="'+el+obj+i+'"
							+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;" class="orange">去盘点</td>'
							+'</tr>');
				}
				
			}else{
//				layer.alert(res.message);
//				$('#fankuiTable').append('<tr class="thin-border-bottom">'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'//id="'+el+obj+i+'"
//						+'	<td style="padding-left: 0px;padding-right: 0px;display: table-cell; vertical-align: middle;">--</td>'
//						+'</tr>');
			}
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
			 console.log(XMLHttpRequest);
			 console.log(textStatus);
			 console.log(errorThrown);
			 hideloading();
		}
	});
	
}
//开始盘点
function startPandian(id,shopcode,shopname,pandianFlag,dudaoNO,dudaoName,longitude,latitude,address){

	
	sessionStorage.setItem("shopcode",shopcode);
	sessionStorage.setItem("shopname",shopname);
	sessionStorage.setItem("dudaoNO",dudaoNO);
	sessionStorage.setItem("dudaoName",dudaoName);
	sessionStorage.setItem("shoplongitude",longitude);
	sessionStorage.setItem("shoplatitude",latitude);
	sessionStorage.setItem("shopaddress",address);
	if(pandianFlag == 1){
		window.location.href='toJiancha_index_list?pandianid='+id;
	}else if(pandianFlag == 10){
		window.location.href='toShop_daodian?pandianid='+id;
	}else{
		layer.msg('此门店不允许进行盘点')
	}
}